﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ThreeByte.ActiveDeck.Config;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using ThreeByte.ActiveDeck.AddIn.Config;
using ThreeByte.Media;
using log4net;
using ThreeByte.ActiveDeck.AddIn.Content.Controls;
using System.IO;
using ThreeByte.ActiveDeck.Content;

namespace ThreeByte.ActiveDeck.Controls
{
    /// <summary>
    /// Interaction logic for NavigatorConfiguration.xaml
    /// </summary>
    public partial class NavigatorConfiguration : UserControl
    {

        private static readonly ILog log = LogManager.GetLogger(typeof(NavigatorConfiguration));

        public NavigatorConfiguration(PageConfig config) {
            InitializeComponent();

            DataContext = config;
        }

        private void AddLayer_Click(object sender, RoutedEventArgs e) {

            //Show the slide chooser
            CoreConfig currentConfig = Globals.ThisAddIn.GetCurrentConfig();
            SlideChooserControl slideChooser = new SlideChooserControl(currentConfig);
            HostForm newDialog = new HostForm(slideChooser);
            if(newDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                Console.WriteLine("Chose a slide");
                PowerPoint.Slide s = slideChooser.SelectedSlide;

                //If a slide is chosen, capture all of the interactive elements and add to a new layer config

                //Create a new LayerConfig
                LayerConfig newLayer = new LayerConfig(slideChooser.SelectedSlide);
                newLayer.Refresh();

                NavigatorConfig config = (NavigatorConfig)DataContext;
                config.Layers.Add(newLayer);
            }
        }

        private void RemoveLayer_Click(object sender, RoutedEventArgs e) {
            //Grab the object and remove it from the collection
            log.Debug("Remove the layer");
            LayerConfig layerToRemove = ((Button)sender).Tag as LayerConfig;
            NavigatorConfig config = (NavigatorConfig)DataContext;
            config.Layers.Remove(layerToRemove);
        }

        private void RefreshLayer_Click(object sender, RoutedEventArgs e) {
            //Grab the object and remove it from the collection
            LayerConfig layerToRefresh = ((Button)sender).Tag as LayerConfig;
            layerToRefresh.Refresh();
        }

    }
}
